$(function(){
    $("#btnpost").click(postData);
})

function postData() {
    let framework = $('#Framework').val(); //技术框架
    let projectType1 = $('#projectType1').val();//1级分类
    let pname = $('#pname').val(); //项目名称
    let pdesc = $('#pdesc').val(); // 项目描述
    let pframework = $('#pframework').val(); // 项目技术组合
  
    let pmodel =  $('.pmodel').val()
    let pmodeldesc =  $('.pmodeldesc').val()

    if (framework==-1 || projectType1 == -1) {
        return layer.msg("技术框架 和 项目大类 必须选择");       
      }

    if (pname.length<=0 || pdesc.length<=0) {
        return layer.msg("项目名称 和 项目描述 必须填写");    
    }

    if (pframework.length<=0) {
        return layer.msg("项目技术组合 必须填写");    
    }
    if ( pmodel.length<=0 || pmodeldesc.length<=0) {
        return layer.msg("项目模块和职责至少有一条数据");    
    }

    let pmodel_arr = [{
        pmodel,
        pmodeldesc
    }];
   
    if(window.domlist.length>0){
        window.domlist.forEach(item=>{
            pmodel_arr.push({
                pmodel:item.find('.pmodel').val(),
                pmodeldesc:item.find('.pmodeldesc').val()
            })
        })
    }
    
    $.ajax({
        type: "post",
        url: "/post/postProject",
        data: {
            framework,
            projectType1,
            pname,
            pdesc,
            pframework,
            pmodel_arr
        },
        success: function (res) {
          // 调用模板引擎
          if (res.data.code == 500) {
            layer.msg(res.data.msg);
            return;
          }
          
          layer.msg(res.data.msg);
        },
      });

}